package swd.work.dataview_wizard_fld_conf;

import com.pub.database.*;
import java.util.*;

public class Business {
   QueryBean gqbnDAO=null;
   public Business(QueryBean pqbnDAO){
      gqbnDAO=pqbnDAO;
   }
   //select * from wkf_dataview_detail where prg_no= and dataview_seqno= and (att_kind='TD' or att_kind='') order by orderby
   String selectTableDataToFld(View view) throws Exception {
   String lstrSQL=null;
   Hashtable<String,Object> lhtTableData=null;
   try{

      lstrSQL="select fields_list,tables_list,sql_condition,orderby_fields,orderby_last_field_seqno,groupby_fields,having_condition,db_alias from wkf_dataview_master where prg_no='"+view.getprg_no()+"' and dataview_seqno='"+view.getdataview_seqno()+"'";
      lhtTableData=gqbnDAO.readSingleRowData(lstrSQL);
      if(lhtTableData==null){
         return "查無資料";
      }

      return "";
   }
   catch(Exception e){
      throw new Exception(e.toString());
   }
   finally{
      lhtTableData.clear();
      lhtTableData=null;
   }
}

   void setInitScreenForSave(View view) throws Exception{
       try{
           view.setfldhidden();//先將所有屬性的欄位隱藏
           if(view.getfield_type()!=null && view.getfield_type().equals("TEXT")){view.settext_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("SELECT")){view.setselect_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("LINK")){view.setlink_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("BUTTON")){view.setbutton_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("CHECKBOX")){view.setcheckbox_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("IMG")){view.setimg_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("HIDDEN")){view.sethidden_display("");};
           if(view.getfield_type()!=null && view.getfield_type().equals("RADIO")){view.setradio_display("");};
           view.setfield_name_readonly(true);
           view.setfield_type_readonly(true);
       }
       catch(Exception e){
           e.printStackTrace();
       }
   }

   String checkNotNullFld(View view) throws Exception{
      StringBuffer lstbNullFldList=new StringBuffer();
      return (lstbNullFldList.toString().equals("") ? "" : lstbNullFldList.delete(lstbNullFldList.length()-1,lstbNullFldList.length()).toString());
   }
}
